import Vue       from 'vue'
import axios     from 'axios'
import qs        from 'qs'
import { Toast } from 'mint-ui';
import { hostUrl,domain } from '@/assets/public'

let authorization = window.localStorage.getItem('Authorization');
if (authorization) {
    axios.defaults.headers.Authorization = authorization;
}
if(process.env.NODE_ENV=='development'){
    axios.defaults.baseURL = hostUrl+'unifast/bhOA/';
}else{
    axios.defaults.baseURL = hostUrl+'unifast/bhOA/'; 
}
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' 

Vue.mixin({
    methods: {
        $_post(url, data) {
            let _self = this;
            if(url.indexOf("?")==-1){
                url = url ;
            }else{
                url = url ;
            }
            return new Promise((resolve, reject) => {
                axios.post(url, qs.stringify(data)).then(res => {
                    resolve(res.data);
                }).catch(function(error) {
                    console.log(error);
                })
            })
        },
        $_get(url, data) {
            let _self = this;
            let corpId = window.localStorage.getItem('corpId');
            if(url.indexOf("?")==-1){
                url = url ;
            }else{
                url = url ;
            }
            return new Promise((resolve, reject) => {
                axios.get(url, {
                    params: data
                }).then(res => {
                    resolve(res.data);
                }).catch(function(error) {
                    console.log(error);
                })
            })
        },
    },
    mounted(){ }
})
